package com.yhcui.monitor.task;

import com.yhcui.monitor.bean.AppInfo;
import com.yhcui.monitor.dao.AppInfoDao;
import com.yhcui.monitor.startup.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.concurrent.BlockingQueue;

@Slf4j
public class PutTask  implements Runnable {

    private AppInfoDao appInfoDao = SpringContextHolder.getBean("appInfoDao");

    private BlockingQueue<AppInfo> queue;

    public PutTask(BlockingQueue<AppInfo> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        log.info("运行存放待检测服务");
        try {
            List<AppInfo> appInfoList = appInfoDao.queryAllAppInfo();
            appInfoList.forEach( appInfo -> {
                try {
                    queue.put(appInfo);
                } catch (InterruptedException e) {
                    log.error("", e);
                }
            });

        } catch (Exception e) {
            log.error("", e);
        }

    }
}
